﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using geetol.sms.core;

namespace geetol.sms.api
{
    public partial class editSmsAPIinfo : Form
    {
        public editSmsAPIinfo()
        {
            InitializeComponent();
        }

        private void BtnSave_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            txtUrl.Text = "http://cs.chinaweimei.com:5001/";
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtUrl.Text) || string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("信息不能为空");
                return;
            }

            weimei_sms_api.api_info api = new weimei_sms_api.api_info();
            api.url = txtUrl.Text.Trim();
            api.user = textBox1.Text.Trim();
            api.pwd = textBox2.Text.Trim();
            config.SaveApi_Info(api);
            weimei_sms_api sms = new weimei_sms_api();
            var r = sms.GetBalance();

            MessageBox.Show(r.returnmsg +" 余额："+ r.balance);
            if (r.status == "0")
                this.Close();
        }

        private void editSmsAPIinfo_Load(object sender, EventArgs e)
        {
            var q = config.LoadApi_Info();
            if(q != null)
            {
                txtUrl.Text = q.url;
                textBox1.Text = q.user;
                textBox2.Text = q.pwd;
            }
        }
    }
}
